﻿using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace ASPNETVN.PORTAL.Modules.PhotoAlbum.Components
{
    public partial class Picture
    {
        public static int UpdateTitle(int id, string title)
        {
            string spName = "[dbo].p_PhotoAlbum_Picture_UpdateTitle";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);
            db.AddInParameter(dbCommand, "@Title", SqlDbType.NVarChar, title);

            return db.ExecuteNonQuery(dbCommand);
        }

        public static DataSet SelectBy_CollectionID_NotInclude_CoverFileName(int collectionID)
        {
            string spName = "[dbo].p_PhotoAlbum_Picture_SelectBy_CollectionID_NotInclude_CoverFileName";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@CollectionID", SqlDbType.Int, collectionID);

            return db.ExecuteDataSet(dbCommand);
        }

        public static void SetCover(int id)
        {
            string spName = "[dbo].p_PhotoAlbum_Picture_SetCover";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ID", SqlDbType.Int, id);

            db.ExecuteNonQuery(dbCommand);
        }
    }
}
